<?php

class VoteMapper extends AbstractMapper
{

    protected function _init()
    {
	$this->setModel(new VoteModel());
	$this->setTableName(VOTE_TABLE);
    }

    public function isVoted($targetId, $targetType, $userId)
    {
	if (!$targetId || !$targetType || !$userId) {
	    return false;
	}

	$data = $this->getAllByQuery(
		array(
		    'select' => array('*'),
		    'from' => VOTE_TABLE,		    
		    'where' => 'target_id = :target_id AND target_type=:target_type AND user_id=:user_id',
		    'params' => array(':target_id' => $targetId, ':target_type' => $targetType, ':user_id' => $userId)
		)
	);
	return !empty($data);
    }

}
